package IO;

import java.io.*;

public class BufferedInputStream1 {
    public static void main(String[] args) throws IOException {
        copy("day10-file_io/src/File3.txt","day10-file_io/src/File4.txt");
    }
    public static void copy(String src,String dest) throws IOException {
        try (InputStream  in = new FileInputStream(src);
             InputStream  in2 = new BufferedInputStream(in);
             OutputStream  out = new FileOutputStream(dest);//用完自动调close
             OutputStream  out2 = new BufferedOutputStream(out)
        ){
            byte[] buffer = new byte[1024];
            int len;
            while ((len = in2.read(buffer)) != -1) {
                out2.write(buffer, 0, len);
            }
            System.out.println("File copied successfully");

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
